package com.ddwl.message.domain.sms.dao;

import com.ddwl.common.dao.TkDao;
import com.ddwl.message.domain.sms.dao.dto.SentSmsFlowDto;
import com.ddwl.message.domain.sms.dao.mapper.SentSmsFlowMapper;
import com.ddwl.message.domain.sms.dao.model.SmsSentFlow;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 类LoanSentSmsFlowDao.java的实现描述：
 *
 * @author zach
 * @Date :2019-04-10 10:55.
 */
@Repository
public class SentSmsFlowDao extends TkDao<SentSmsFlowMapper, SmsSentFlow> {

    @Resource
    private SentSmsFlowMapper sentSmsFlowMapper;

    /**
     * 短信查询接口
     * @param dto
     * @return
     */
    public List<SmsSentFlow> getPage(SentSmsFlowDto dto){
        Example example = getExample(dto);
        List<SmsSentFlow> loanSmsSentFlows = sentSmsFlowMapper.selectByExample(example);
        return loanSmsSentFlows;
    }

    /**
     * 短信数量查询接口
     * @param dto
     * @return
     */
    public Integer getSmsCount(SentSmsFlowDto dto){
        Integer smsCount = sentSmsFlowMapper.getSmsCount(dto);
        return smsCount;
    }

    /**
     * 私有构造条件
     * @param dto
     * @return
     */
    private Example getExample(SentSmsFlowDto dto) {
        Example example = new Example(SmsSentFlow.class);
        Example.Criteria criteria = example.and();
        criteria.andEqualTo("toPhone", dto.getToPhone())
                .andEqualTo("serialNumber", dto.getSerialNumber())
                .andEqualTo("event", dto.getEvent())
                .andEqualTo("channel", dto.getChannel())
                .andBetween("createTime", dto.getStartTime(), dto.getEndTime());
        return example;
    }

    public List<SmsSentFlow> getAll() {
        Example example = new Example(SmsSentFlow.class);
        return sentSmsFlowMapper.selectByExample(example);
    }

    public void changeId(Map<String, String> map) {
        sentSmsFlowMapper.changeId(map);
    }
}
